<template>
  <div class="main">
    <div class="left">
      <studentMainleft></studentMainleft>
    </div>
    <div class="right">
      <div class="add">
        <el-button type="primary" @click="open(1)">新增学院</el-button>
      </div>
      <template>
        <el-table
          :data="college"
          style="width: 100%"
          max-height="90%"
          :highlight-current-row="true"
        >
          <el-table-column prop="CollegeId" label="学院编号" width="350" align="center"></el-table-column>
          <el-table-column prop="CollegeName" label="学院名称" width="400" align="center"></el-table-column>
          <el-table-column label="操作" width="300" align="center">
            <el-link type="primary" @click="open(2)">编辑</el-link>
            <el-link type="primary">班级管理</el-link>
          </el-table-column>
        </el-table>
      </template>
    </div>
  </div>
</template>

<script>
import studentMainleft from "@/components/studentMainleft";
export default {
  components: {
    studentMainleft
  },
  data() {
    return {
      college: [],
      classtable: [
        {
          id: 1,
          classId: "2020030903",
          collegeid: 1
        },
        {
          id: 1,
          classId: "2020030902",
          collegeid: 1
        }
      ]
    };
  },
  created() {
    this.GetAllCollege();
  },
  mounted() {},
  methods: {
    open(flag) {
      this.$prompt("请输入学院名称", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      })
        .then(({ value }) => {
          if (flag == 1) {
            this.$axios({
              method: "post",
              url: this.$api.InsertCollege,
              data: { CollegeName }
            }).then(res => {
              this.$message({
                type: "success",
                message: "添加成功"
              });
            });
          }else{
              this.$axios({
               method:'put',
               url:this.$api.UpdateCollege,
              data:{},
               }).then((res)=>{
               console.log(res)
              })
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    },
    GetAllCollege() {
      this.axios({
        method: "get",
        url: this.$api.GetAllCollege
      }).then(res => {
        console.log(res);
        this.college = res.data.message;
      });
    }
  }
};
</script>

<style scoped>
.main {
  display: flex;
  height: 100%;
}
.right {
  width: 100%;
  background-color: white;
  height: 80%;
  margin-left: 10px;
  padding: 30px 30px 0px 30px;
}
.right .add {
  text-align: left;
}
</style>
